<%@ page language="java" isELIgnored="false"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<%@ include file="/WEB-INF/jsp/ResourceGlobal.jsp"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<html>

	<head>
		<!-- 这里引入导航信息header.tpl -->
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>下载产出</title>
		<style type="text/css">
			.download {
			    color: #666;
			    padding: 6px;
			    font-size: 12px;
			}
			
			.download:hover {
			    color: #f5a014;
			}
		</style>
	</head>
	
	<body class="sub-page" style="height: auto">
		<div style="padding-bottom: 50px">
			<input type="hidden" id="serviceType" value="${serviceType }"/>
			<table class="table" style="border: solid 1px #ccc; margin:10px auto; width: 96%">
				<colgroup>
                   	<col width="5%">
                   	<col width="20%">
                   	<col width="20%">
                   	<col width="20%">
                   	<col width="25%">
                   	<col width="10%">
             	</colgroup>
             	<thead>
					<tr style="background: rgb(246,246,246)">
						<td><input type="checkbox" name="all"></td>
						<td>产品名称</td><td>待办日期</td><td>待办类型</td><td>描述</td><td>操作</td>
					</tr>
				</thead>
				<tbody id="prds">
					<c:forEach var="dto" items="${complateTodos}">
						<tr>
							<td><input type="checkbox" name="row" data-attid="${dto.id}"></td>
							<c:choose>
								<c:when test="${empty dto.prjSname }">
									<td>--</td>
								</c:when>
								<c:otherwise>
									<td>${dto.prjSname}</td>
								</c:otherwise>
							</c:choose>
							<td>
								<fmt:formatDate value="${dto.todoDate }" pattern="yyyy-MM-dd"/>
							</td>
							<td>${dto.todoTypeName}</td>
							<td></td>
							<td><a href="javascript:;" class="download" title="下载" onclick="downloadSingle('${dto.id}', 'single');">下载</a></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<div style="position: fixed; bottom: 0; padding: 10px; width: 100%; background: white;">
				<button style="height: 32px" class="btn btn-default btn-sm" onclick="downloadMulti();"><i class="fa fa-arrow-down"></i>&nbsp;批量下载</button>
			</div>
		</div>
		
		<script type="text/javascript">
			$(function() {
				$("input[name=all]").click(function () {
			        if (this.checked) {
			            $("input[name=row]").prop("checked", true);
			        } else {
			            $("input[name=row]").prop("checked", false);
			        }
			    });
			});
			
			function downloadMulti() {
				var prds = [];
				$.each($("input[name=row]"), function() {
	                if(this.checked){
	                	prds.push($(this).data("attid"));
	                }
	            });
				if(prds.length == 0) {
					toastr.warning('', '请选择要下载的产品');
					return;
				}
				downloadSingle(prds.join(","), 'multi');
			}
			
			function downloadSingle(ids, type) {
				var serviceType = $("#serviceType").val();
				post('<%=context%>' + 'business/myHome/todoAndOutput/downloadOutput.do', {ids: ids, type: type, serviceType: serviceType});
			}
			
			//post 提交下载表单
			function post(url, params) {
				var temp_form = document.createElement("form");      
				temp_form.action = url;
				temp_form.target = "_self";
				temp_form.method = "post";
				temp_form.style.display = "none";
				for (var x in params) {
					var opt = document.createElement("input");
				    opt.name = x;
				    opt.value = params[x];
				    temp_form.appendChild(opt);
				}
				document.body.appendChild(temp_form);
				temp_form.submit();
			}
		</script>
	</body>
</html>